#!/usr/bin/python
# Copyright (C) 2003, Charles Wang.
# Author:  Charles Wang <charles@linux.net.cn>
# All rights reserved.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the Free
# Software Foundation; either version 2, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANT; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public LIcense for more
# details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, 59 Temple
# Place - Suite 330, Boston, MA 02111-1307, USA.

import os

def  crange(c_from, c_to):
    return  map(lambda i: chr(i), range(ord(c_from), ord(c_to)))

def  ram(prefix, r=None):
    if r:
        for v in r:
            if v >= 0 and v <= 19:
                os.mknod(os.path.join(prefix, 'ram%d' % v),
                         0660 | stat.S_IFBLK,
                         os.makedev(1, v))
    else:
        os.symlink('ram1', os.path.join(prefix, 'ram'))

def  ramdisk(prefix):
    os.symlink('ram0', os.path.join(prefix, 'ramdisk'))

def  hd(prefix, r0, r1=None):
    m = { 'a': (3,   0), 'b': (3,  64), 'c': (22,  0), 'd': (22, 64),
          'e': (33,  0), 'f': (33, 64), 'g': (34,  0), 'h': (34, 64),
          'i': (56,  0), 'j': (56, 64), 'k': (57,  0), 'l': (57, 64),
          'm': (88,  0), 'n': (88, 64), 'o': (89,  0), 'p': (89, 64),
          'q': (90,  0), 'r': (90, 64), 's': (91,  0), 't': (91, 64) }
    for v0 in r0:
        if v0 >= 'a' and v0 <= 't':
            if r1:
                for v1 in r1:
                    if v1 >= 1 and v1 <= 32:
                        os.mknod(os.path.join(prefix, 'hd%c%d' % (v0, v1)),
                                 0660 | stat.S_IFBLK,
                                 os.makedev(m[v0][0], m[v0][1] + v1))
            else:
                os.mknod(os.path.join(prefix, 'hd%c' % v0),
                         0660 | stat.S_IFBLK,
                         os.makedev(m[v0][0], m[v0][1]))
